package com.lineage.data.item_etcitem.quest2;

import com.lineage.data.executor.ItemExecutor;
import com.lineage.server.model.Instance.L1DoorInstance;
import com.lineage.server.model.Instance.L1ItemInstance;
import com.lineage.server.model.Instance.L1PcInstance;
import com.lineage.server.model.L1Object;
import com.lineage.server.serverpackets.S_ServerMessage;
import com.lineage.server.serverpackets.ServerBasePacket;
import com.lineage.server.world.World;
import java.util.Iterator;

public class DragonDoorKeyC2 extends ItemExecutor {
  public static ItemExecutor get() {
    return new DragonDoorKeyC2();
  }
  
  public void execute(int[] data, L1PcInstance pc, L1ItemInstance item) {
    if (pc.getMapId() == 1017) {
      pc.getInventory().removeItem(item, 1L);
      Iterator<L1Object> iterator = World.get().getVisibleObjects(1017).values().iterator();
      while (iterator.hasNext()) {
        L1Object obj = iterator.next();
        if (obj instanceof L1DoorInstance) {
          L1DoorInstance door = (L1DoorInstance)obj;
          if (door.get_showId() != pc.get_showId() || door.getDoorId() != 10038)
            continue; 
          door.open();
          door.deleteMe();
        } 
      } 
    } else {
      pc.sendPackets((ServerBasePacket)new S_ServerMessage(79));
    } 
  }
}
